package com.freshcity.page.common
{
	import com.freshcity.ILayer;
	import com.freshcity.common.UserHomelWin;
	import com.freshcity.component.container.Component;
	import com.freshcity.component.container.Window;
	import com.freshcity.core.BaseHomeWin;
	import com.freshcity.core.Dispatcher;
	import com.freshcity.core.MainScene;
	import com.freshcity.friend.HomeWin;
	import com.freshcity.lib.event.EventName;
	import com.freshcity.manager.LayerManager;
	import com.freshcity.page.home.FriendShow;
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	
	import fl.events.ListEvent;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.Dictionary;
	
	public class UserHome extends Window
	{
		public static const SEND_WORD:int = 1;
		
		public var back:UserHomelWin;
		public var userId:String;
		protected var container:DisplayObjectContainer;
		protected var _contains:Dictionary=new Dictionary();
		
		private var _data:*;
		private var user:Object;
		private var report:Object;
		
		public function UserHome(parent:ILayer=null, xpos:Number=0, ypos:Number=0)
		{
			this.layer = LayerManager.sceneLayer;
			super(this.layer, xpos, ypos, "个人主页");
			this.visible = false;
			this.hasCloseButton = true;
			this.setSize(640,420); //140,45
			back.tabMenu.addEventListener(ListEvent.ITEM_CLICK, drawContent);
			Dispatcher.addEventListener(EventName.StartTalk, hide);
		}
		
		protected function initContent(index:int):void
		{
			var c:*;
			switch (index)
			{
				case 1:
				{
					c=new FriendDetail();
					break;
				}
				case 2:
				{
					c=new TreeDetail();
					break;
				}
				case 3:
				{
					c=new CommentDetail();
					break;
				}
				default:
				{
					c=new UserDetail();
					break;
				}					
			}
			c.main=this.main;
			c.home=this;
			_contains[index]=c;
		}
		
		protected function drawContent(event:ListEvent):void
		{
			var index:int=event.index;
			var content:Component;
			
			if (_contains[index] == null)
				initContent(index);
			content=_contains[index];
			while (container.numChildren > 0)
				container.removeChildAt(0);
			container.addChild(content);
			content.show();
		}
		
		override protected function addChildren():void
		{
			super.addChildren();
			back = new UserHomelWin();
			addChild(back);
			
			container=back.container;
			container.mouseEnabled=false;
			container.tabEnabled=false;
		}
		
		override public function hide(event:Event=null):void
		{
			TweenMax.to(this, 0.3, {y: "-50", autoAlpha: 0});
		}
		
		override public function show(event:Event=null):void
		{
			this.layer.setTop(this);
			
			back.tabMenu.selectedIndex = 0;
			back.tabMenu.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, true, 0, 0, 0));
			
			this.x=(stage.stageWidth - width) / 2;
			this.y=(stage.stageHeight - height) / 2 - 50;
			TweenMax.to(this, 0.3, {y: "+50", autoAlpha: 1});
		}
		
		public function forwardPage(index:int):void
		{
			back.tabMenu.selectedIndex = index;
			back.tabMenu.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, true, 0, 0, index));
		}
		
		override public function destroy():void
		{
			// TODO Auto Generated method stub
			super.destroy();
		}
		
		override public function draw():void
		{
			// TODO Auto Generated method stub
			super.draw();
		}

		public function get data():*
		{
			return _data;
		}

		public function set data(value:*):void
		{
			_data = value;
			this.user=data.user;
			this.report=data.report;
			userId = data.user.id;
			//根据性别设置菜单
			if (this.user.sex == 'female')
			{
				//back.tabMenu.arrBtnLabels=["基本信息", "梧桐树", "他人评价"];
				back.tabMenu.arrBtnLabels=["基本信息","关于交友", "梧桐树"];
			}else{
				back.tabMenu.arrBtnLabels=["基本信息","关于交友"];
			}
			this.show();
		}
		
	}
}